package com.sniff.atp.modules.test.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sniff.atp.common.api.CommonPage;
import com.sniff.atp.common.api.CommonResult;
import com.sniff.atp.modules.test.model.DemandReport;
import com.sniff.atp.modules.test.model.MobilePhoneLog;
import com.sniff.atp.modules.test.service.DemandReportService;
import com.sniff.atp.modules.test.service.MobilePhoneLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  手机借用操作日志
 * </p>
 *
 * @author macro
 * @since 2023-11-28
 */
@RestController
@RequestMapping("/test/mobilePhoneLog")
@Api(value = "手机操作日志", tags = "手机操作日志")

public class MobilePhoneLogController {
    @Autowired
    private MobilePhoneLogService mobilePhoneLogService;

    @ApiOperation("新增日志")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody MobilePhoneLog mobilePhoneLog) {
        boolean success = mobilePhoneLogService.create(mobilePhoneLog);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("修改操作日志")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@RequestBody MobilePhoneLog mobilePhoneLog) {

        boolean success = mobilePhoneLogService.update(mobilePhoneLog.getMobileId(), mobilePhoneLog);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("根据ID获取需求详情")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<MobilePhoneLog> getItem(@PathVariable Long id) {
        MobilePhoneLog mobilePhoneLog = mobilePhoneLogService.getById(id);
        return CommonResult.success(mobilePhoneLog);
    }

    @ApiOperation("根据ID删除问题列表")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@PathVariable Long id) {
        boolean success = mobilePhoneLogService.removeById(id);

        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("分页查询问题")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<MobilePhoneLog>> list(@RequestBody MobilePhoneLog mobilePhoneLog) {
        if(mobilePhoneLog.getPageSize() == null){
            mobilePhoneLog.setPageSize(10);
        }
        if(mobilePhoneLog.getPageNum() == null){
            mobilePhoneLog.setPageNum(1);
        }
        Page<MobilePhoneLog> menuList = mobilePhoneLogService.list(mobilePhoneLog, mobilePhoneLog.getPageSize(), mobilePhoneLog.getPageNum());
        return CommonResult.success(CommonPage.restPage(menuList));
    }
}

